package com.shxt.framework.rbac.weeklycontent.web;


import com.shxt.framework.commons.controller.BaseController;
import com.shxt.framework.rbac.weeklycontent.model.WeeklyContent;
import com.shxt.framework.rbac.weeklycontent.service.WeeklyContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 周报文章
 * @date 2019-12-04
 */
@Controller
@RequestMapping("/weeklyContent")
public class WeeklyContentController extends BaseController {

    @Autowired
    private WeeklyContentService weeklyContentService;

    /**
     * 获取周报列表
     * @param model
     * @return
     */
    @RequestMapping("/contentPage")
    public ModelAndView contentPage(ModelAndView model) {
        model.addObject("pageData", weeklyContentService.getAllWeeklyContentList());
        return model;
    }

    @ResponseBody
    @PostMapping("/content")
    public String addContent(@RequestBody  WeeklyContent weeklyContent, ModelAndView model) {
        weeklyContent.setUser_id(getLoginUser().getUser_id());
        weeklyContentService.add(weeklyContent);
        return "ok";
    }

    @ResponseBody
    @PutMapping("/content")
    public String updateContent(@RequestBody  WeeklyContent weeklyContent, ModelAndView model) {
        weeklyContentService.update(weeklyContent);
        return "ok";
    }

    @ResponseBody
    @DeleteMapping("/content")
    public String deleteContent(@RequestBody  WeeklyContent weeklyContent, ModelAndView model) {
        weeklyContentService.updateAndDeleteWCStatus(weeklyContent);
        return "ok";
    }

    @ResponseBody
    @PostMapping("/queryContent")
    public ResponseEntity<List> queryContent(@RequestBody  WeeklyContent weeklyContent, ModelAndView model) {
        return ResponseEntity.ok(weeklyContentService.query(weeklyContent));
    }

}
